// Michael Depuy
// depuym@onid.orst.edu
// CS311-400
// Homework 4

#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>


void proc_sigusr1(int signal){
  printf("SIGUSR1 has been caught.\n");
}

void proc_sigusr2(int signal){
  printf("SIGUSR2 has been caught.\n");
}

void proc_sigint(int signal){
  printf("SIGINT has been caught, terminating the program.\n");
  exit(EXIT_SUCCESS);
}

int main(int argc, char *argv[]){
  struct sigaction usr_sig1,usr_sig2,usr_sigint;

  sigemptyset(&usr_sigint.sa_mask);
  sigemptyset(&usr_sig1.sa_mask);
  sigemptyset(&usr_sig2.sa_mask);
  usr_sigint.sa_flags = 0;
  usr_sig1.sa_flags = 0;
  usr_sig2.sa_flags = 0;
  usr_sigint.sa_handler = proc_sigint;
  usr_sig1.sa_handler = proc_sigusr1;
  usr_sig2.sa_handler = proc_sigusr2;

  if(sigaction(SIGINT,&usr_sigint,NULL) == -1)
    exit(EXIT_FAILURE);

  if(sigaction(SIGUSR1,&usr_sig1,NULL) == -1)
    exit(EXIT_FAILURE);

  if(sigaction(SIGUSR2,&usr_sig2,NULL) == -1)
    exit(EXIT_FAILURE);

  kill(getpid(),SIGUSR1);
  kill(getpid(),SIGUSR2);
  kill(getpid(),SIGINT);

  return EXIT_SUCCESS;
}
